package com.yycx.module.system.provider.service.impl;

import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.module.system.client.entity.SysDict;
import com.yycx.module.system.client.entity.SysProject;
import com.yycx.module.system.provider.mapper.SysProjectMapper;
import com.yycx.module.system.provider.service.SysProjectService;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.model.ResultBody;
import org.springframework.stereotype.Service;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.query.CriteriaQuery;
import org.springframework.transaction.annotation.Propagation;
import com.yycx.common.mybatis.query.CriteriaSave;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 项目接口实现类
 *
 * @author flyme
 * @date 2024-07-09
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysProjectServiceImpl extends BaseServiceImpl<SysProjectMapper, SysProject> implements SysProjectService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, SysProject project, EntityMap extra) {
        return ResultBody.ok();
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<SysProject> cq, SysProject project, EntityMap requestMap) {
        cq.orderByDesc("project.createTime");
        Integer projectType = project.getProjectType();
        if (FlymeUtils.isNotEmpty(projectType)) {
            cq.eq("projectType", projectType);
        }
        return ResultBody.ok();
    }

    @Override
    public ResultBody beforeListEntityMap(CriteriaQuery<SysProject> cq, SysProject sysProject, EntityMap requestMap) {
        String projectGroup = sysProject.getProjectGroup();
        if (FlymeUtils.isNotEmpty(projectGroup)) {
            cq.like("projectGroup", projectGroup);
        }
        //已启用
        cq.eq(true,"projectState",1);
        return ResultBody.ok();
    }

    @Override
    public List<SysProject> listByIds(String projectIds) {
        CriteriaQuery cq = new CriteriaQuery(SysProject.class);
        cq.in("projectId", projectIds.split(","));
        return list(cq);
    }
}
